package com.le.tester.controller;

import com.le.tester.common.ServerResponse;
import com.le.tester.dto.CommentLikeDto;
import com.le.tester.entity.CommentLike;
import com.le.tester.sevice.CommentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 描述：评论控制层
 */
@Controller
@RequestMapping("/comment/")
public class CommentController {
    private static final Logger LOG = LoggerFactory.getLogger(CommentController.class);

    @Autowired
    private CommentService commentService;

    @ResponseBody
    @RequestMapping(value = "likeOrUnlike")
    public ServerResponse<Map<String, List<CommentLikeDto>>> commentLikeOrUnlike(@RequestBody CommentLikeDto commentLikeDto) {
        //检验参数
        try {
            Map<String, List<CommentLikeDto>> resultComment = commentService.commentLikeOrUnlike(commentLikeDto);
            return ServerResponse.createBySuccess(resultComment);
        } catch (Exception e) {
            LOG.info("点赞异常：{}", e.getMessage());
            return ServerResponse.createByErrorMessage(e.getMessage());
        }

    }
}
